var a = require("../common.js"), t = getApp();

Page({
    behaviors: [ a ],
    data: {
        incomeType: "0",
        memberId: "",
        keyword: "",
        page: 1,
        isLoadMore: !0,
        total_page: 0,
        listData: [],
        networkLoading: !1
    },
    onLoad: function(a) {
        a.id && this.setData({
            memberId: a.id
        }), this.getListData();
    },
    initCustomField: function() {
        wx.setNavigationBarTitle({
            title: this.data.balance_text + "明细"
        });
    },
    handSearch: function(a) {
        this.data.keyword = a.detail, this.getListData();
    },
    initPage: function() {
        this.setData({
            listData: [],
            networkLoading: !1
        }), this.data.page = 1, this.data.total_page = 0, this.data.isLoadMore = !0;
    },
    changeType: function(a) {
        this.data.incomeType = a.detail.name, this.getListData();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore && this._getMoreData();
    },
    getListData: function() {
        var a = this;
        this.initPage();
        var e = {};
        e.search = {
            type: 0 == this.data.incomeType ? "" : this.data.incomeType,
            member: this.data.keyword
        }, this.data.memberId && (e.member_id = this.data.memberId);
        var i = t.getNetAddresss("plugin.shop-assistant.frontend.member.balance-list");
        t._postNetWork({
            url: i,
            data: e,
            success: function(e) {
                var i = e.data;
                if (1 != i.result) return t.tips(i.msg);
                a.data.total_page = i.data.last_page, a.data.total_page || (a.data.total_page = 0), 
                a.setData({
                    listData: i.data.data,
                    networkLoading: !0
                });
            }
        });
    },
    _getMoreData: function() {
        var a = this;
        if (this.data.isLoadMore = !1, !(this.data.page >= this.data.total_page)) {
            this.data.page += 1;
            var e = {
                page: this.data.page
            };
            e.search = {
                type: 0 == this.data.incomeType ? "" : this.data.incomeType,
                member: this.data.keyword
            }, this.data.memberId && (e.member_id = this.data.memberId);
            var i = t.getNetAddresss("plugin.shop-assistant.frontend.member.balance-list");
            t._postNetWork({
                url: i,
                data: e,
                success: function(t) {
                    var e = t.data;
                    if (a.data.isLoadMore = !0, 1 === e.result) {
                        var i = a.data.listData.concat(e.data.data);
                        a.setData({
                            listData: i
                        });
                    } else a.data.page = a.data.page - 1, a.data.isLoadMore = !1;
                }
            });
        }
    },
    onShareAppMessage: function() {}
});